//
//  PhoneNumTableViewController.m
//  Consume100
//
//  Created by eliot on 16/3/23.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "PhoneNumTableViewController.h"

@interface PhoneNumTableViewController ()
@property (nonatomic, strong) UITextField *textField;
@end

@implementation PhoneNumTableViewController

/**
 *  MARK：XIB创建
 *
 *  @return
 */

+(PhoneNumTableViewController*)CreatPhoneNumTableViewController{
    
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    PhoneNumTableViewController  *phoneNumTableViewController=[story instantiateViewControllerWithIdentifier:@"PhoneNumTableViewController"];
    
    return phoneNumTableViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"联系电话";
    //设置tableView背景颜色
    self.tableView.backgroundColor = [UIColor colorWithRed:237/255.0 green:237.2/255.0 blue:237/255.0 alpha:1];
    //设置title颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor colorWithRed:38/255.0 green:94/255.0 blue:215/255.0 alpha:1]}];
    // self.title = @"昵称";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveAndDismiss)];
//    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.tableView.tableFooterView = [[UIView alloc] init];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    
    
    
    
    
    
}

//点击保存按钮
- (void)saveAndDismiss {
    
    NSDictionary *dic = [NSDictionary dictionaryWithObject:self.textField.text forKey:@"PhoneNum"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changePhoneNum" object:nil userInfo:dic];
    
    [UIView animateWithDuration:1.5 animations:^{
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    self.textField = [[UITextField alloc] init];
    [cell.contentView addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-40);
    }];
    self.textField.text = self.currentPhoneNum;
    self.textField.placeholder = @"请输入联系电话";
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cell.contentView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(9);
        make.bottom.mas_equalTo(-9);
        make.left.mas_equalTo(self.textField.mas_right).mas_equalTo(6);
    }];
    [btn setImage:[UIImage imageNamed:@"btn_clear_40x40"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clearBtnClick) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

//点击清除按钮
- (void)clearBtnClick {
    self.textField.text = @"";
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
